package com.nccsjz.base;

/**
 * BaseAction.java文件是所有Action子类的父类 
 */

import java.io.File;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.ServletActionContext;

import utils.ConfigUtils;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 
 * @author jason
 * 
 */
@SuppressWarnings("serial")
public abstract class BaseAction extends ActionSupport {

	/** INDEX String 返回首页的逻辑路径 "index" */
	protected static final String INDEX = "index";

	/** DEFAULT String 返回欢迎页面的逻辑路径 "default" */
	protected static final String DEFAULT = "default";

	/**
	 * getSession方法用于获取与Action相关连的会话
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	protected Map<String, Object> getSession() {
		return ActionContext.getContext().getSession();
	}

	/**
	 * 根据给定的路径得到服务器路径
	 * 
	 * @param path
	 *            路径
	 * @return String 绝对路径
	 */
	protected String getContextPath() {
		return ServletActionContext.getServletContext().getContextPath();
	}

	
	
	protected String getContextRealPath(String path) {
		String levelOnePath = ServletActionContext.getServletContext()
				.getRealPath(ConfigUtils.getAppConfig("levelOnePath"));
		return StringUtils.join(new String[] { levelOnePath, File.separator,
				path });
	}
}
